package com.work.filter;

import com.work.common.result.Result;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import java.util.Enumeration;
import java.util.Objects;

@Slf4j
@Aspect
@Component
public class RequestFilter {

    @Pointcut("execution(* com.ljh.worksb.controller..*.*(..))")
    public void pointcut() {

    }

//    @Before("pointcut()")
//    public void apiBefore(JoinPoint joinPoint) {
//        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
//        if (Objects.isNull(requestAttributes)) {
//            log.warn("无请求参数!");
//            return;
//        }
//        HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
//        final Enumeration<String> headerNames = request.getHeaderNames();
//        while (headerNames.hasMoreElements()) {
//            String name = headerNames.nextElement();
//            String value = request.getHeader(name);
//            log.info("请求头名称:{} 请求头值:{}", name, value);
//        }
//    }
}
